package org.itboys.mobile.util;

import org.apache.commons.lang3.StringUtils;
import org.itboys.commons.utils.servlet.ServletContextHolder;
import org.itboys.mobile.common.SundayCommonConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 通过accountId获取某些重要值
 * Created by Administrator on 2017/3/6.
 */
public class Test {
    private long id ;
    private String code;
    private Integer store;
    public Test() {
    }

    public Test(long id, String code, Integer store) {
        this.id = id;
        this.code = code;
        this.store = store;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getStore() {
        return store;
    }

    public void setStore(Integer store) {
        this.store = store;
    }




    public static void main(String[] args) {
        List<Test> olds = new ArrayList<Test>();
        olds.add(new Test(1,"01",1));
        olds.add(new Test(2,"02",2));
        olds.add(new Test(3,"03",3));
        olds.add(new Test(4,"04",4));
        olds.add(new Test(5,"05",5));


        List<Test> news = new ArrayList<Test>();
        news.add(new Test(0,"01",1));
        news.add(new Test(0,"02",22));
        news.add(new Test(0,"03",33));

        news.add(new Test(0,"06",6));
        news.add(new Test(0,"07",7));


        List<Test> needToAdd = new ArrayList<Test>();
        List<Test> needToUpdate = new ArrayList<Test>();
        List<Test> needToDelete = new ArrayList<Test>();
        List<Test> needToStay = new ArrayList<Test>();
        for(Test n:news){
            boolean isNeedToAdd =true;

            for(Test o:olds){
                if(o.getCode().equalsIgnoreCase(n.getCode())){
                    isNeedToAdd=false;
                    if(o.getStore()==n.getStore()){
                       // isNeedToUpdate=true;
                        needToStay.add(new Test(o.getId(),o.getCode(),n.getStore()));
                    }else{
                        needToUpdate.add(new Test(o.getId(),o.getCode(),n.getStore()));
                    }
                    break;
                }
            }
            if(isNeedToAdd){
                needToAdd.add(n);
            }



            /*if(!isNeedToAdd&&isNeedToDelete){
                needToAdd.add(n);
            }*/
        }
        for(Test test:needToAdd){
            System.out.println("需要新增的Id="+test.getId()+"，code="+test.getCode()+"，store="+test.getStore());
        }
        for(Test test:needToUpdate){
            System.out.println("需要修改的Id="+test.getId()+"，code="+test.getCode()+"，store="+test.getStore());
        }

        for(Test test:needToStay){
            System.out.println("保持不变的Id="+test.getId()+"，code="+test.getCode()+"，store="+test.getStore());
        }
        olds.removeAll(needToUpdate);
        olds.removeAll(needToStay);
        List<Test> needToStay2 = new ArrayList<Test>();
        olds.removeAll(needToStay2);
        for(Test test:olds){
            System.out.println("需要删除的Id="+test.getId()+"，code="+test.getCode()+"，store="+test.getStore());
        }


    }
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Test) {
            Test t = (Test) obj;
            return t.id==this.id&&t.code==this.code;
        }
        return false;
    }

}
